/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *   02110-1301, USA.
 * 
 * $Id: MapGeneratorTools.java 35 2008-05-05 14:16:37Z jens464 $
*/
package albareth.generator;

import albareth.core.GameMap;
import albareth.core.entity.Ground;
import frosch.util.WeightedSet;


public final class MapGeneratorTools
{
    
    /**
     * Fills a rectancle on the given map with the given ground tile.
     */
    public static void fillMapRect(GameMap map, int x, int y, int w, int h, Ground ground)
    {
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                map.setGround(ground, x + i, y + j);
            }
        }
    }

    /**
     * Fills a rectancle on the given map with random ground tiles from the given set.
     */
    public static void fillMapRect(GameMap map, int x, int y, int w, int h, WeightedSet groundSet)
    {
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                map.setGround((Ground)groundSet.randomElement(), x + i, y + j);
            }
        }
    }

    /**
     * Draws an unfilled rectancle on the given map with the given ground tile.
     */
    public static void drawMapRect(GameMap map, int x, int y, int w, int h, Ground ground)
    {
        for (int i = 0; i < w; i++) {
            map.setGround(ground, x+i, y);
            map.setGround(ground, x+i, y+h-1);
        }
        for (int j = 0; j < h; j++) {
            map.setGround(ground, x, y+j);
            map.setGround(ground, x+w-1, y+j);
        }
    }

    /**
     * Draws an unfilled rectancle on the given map with random ground tiles
     * from the given weighted set of ground tiles.
     */
    public static void drawMapRect(GameMap map, int x, int y, int w, int h, WeightedSet groundSet)
    {
        for (int i = 0; i < w; i++) {
            map.setGround((Ground)groundSet.randomElement(), x+i, y);
            map.setGround((Ground)groundSet.randomElement(), x+i, y+h-1);
        }
        for (int j = 0; j < h; j++) {
            map.setGround((Ground)groundSet.randomElement(), x, y+j);
            map.setGround((Ground)groundSet.randomElement(), x+w-1, y+j);
        }
    }
}
